<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta name="renderer" content="webkit" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>千锋教育大前端Vue教学</title>
  <!-- 引入vue -->
  <script src="https://cdn.staticfile.org/vue/3.0.5/vue.global.js"></script>
</head>

<body style="margin:100px;font-size:22px;">
  <div id="app">
    <Man name="尤勇" like="下棋"></Man>
    <Woman name="夏琪" like="游泳"></Woman>
  </div>
  <script>
    const PeopleMixin = {
      props: ['name'],
      data() {
        return {
          eye: '黑色',
        }
      },
      methods: {
        doLike(name) {
          return '我喜欢' + name;
        }
      },
      mounted() {
        console.log('我是在mixin中的mounted');
      }
    };
    const Man = {
      template: `<div>我是{{type}}，我眼睛{{eye}}，名叫{{name}}，{{doLike(like)}}</div>`,
      mixins: [PeopleMixin],
      props: ['like'],
      data() {
        return {
          type: "男生",
        }
      },
      mounted() {
        console.log('我是在Man中的mounted');
      }
    };
    const Woman = {
      template: `<div>我是{{type}}，我眼睛{{eye}}，名叫{{name}}，{{doLike(like)}}</div>`,
      mixins: [PeopleMixin],
      props: ['like'],
      data() {
        return {
          type: "女生",
        }
      },
      mounted() {
        console.log('我是在Man中的mounted');
      }
    };
    // 创建应用
    const app = Vue.createApp({
      components: { // 局部注册组件
        Man,
        Woman,
      }
    });
    // 挂载应用
    app.mount('#app');
  </script>
</body>

</html>